package com.softer.wxzj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.common.util.StringUtils;
import com.softer.wxzj.entity.HouseAndOwner;
import com.softer.wxzj.entity.RefReq;
import com.softer.wxzj.entity.RefReqList;
import com.softer.wxzj.mapper.BaseOwnerInfoMapper;
import com.softer.wxzj.mapper.RefReqListMapper;
import com.softer.wxzj.mapper.RefReqMapper;
import com.softer.wxzj.service.RefReqListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * RefReqListService class
 * @author zcz
 * @date 2019/7/10
 */
@Service
public class RefReqListServiceImpl implements RefReqListService {

    @Autowired
    RefReqListMapper refReqListMapper;
    @Autowired
    RefReqMapper refReqMapper;
    @Autowired
    BaseOwnerInfoMapper baseOwnerInfoMapper;
    @Override
    public PageInfo<RefReqList> getAuditList(Page page, String id) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<RefReqList> list = refReqListMapper.getAuditList(id);
        list.forEach(l -> l.setPayAccrCal(l.getPayAccrCal().add(l.getPayAccrAmount())));
        PageInfo<RefReqList> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 退款信息
     * @param houseAndOwner
     * @return
     */
    @Override
    public PageInfo<HouseAndOwner> selectOwnerByHouseId(Page page,HouseAndOwner houseAndOwner) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<HouseAndOwner> list;
        if (StringUtils.isBlank(houseAndOwner.getFuzzy())){
            list=refReqListMapper.selectOwnerByHouseId(houseAndOwner);
        }else {
            list=refReqListMapper.selectOwnerByHouseIdFuzzy(houseAndOwner.getId(),houseAndOwner.getFuzzy());
        }
        PageInfo<HouseAndOwner> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<RefReqList> getBatchRefReqListDetail(Page page, RefReq refReq) {
        //判断是否记账   记账用户查log  否则查业主
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<RefReqList> list = refReqListMapper.getBatchRefReqListDetail(refReq);
        List<RefReqList> collect = list;
        if(StringUtils.isNotEmpty(refReq.getFuzzy()) ){
            collect = list.stream().filter(l -> l.getFuzzy().indexOf(refReq.getFuzzy()) != -1).collect(Collectors.toList());
        }
        PageInfo<RefReqList> pageInfo = new PageInfo<>(collect);
        return pageInfo;
    }

    @Override
    public CommonResult insert(RefReqList refReqList) {
        return null;
    }

    @Override
    public CommonResult update(RefReqList refReqList) {
        return null;
    }

    @Override
    public CommonResult delete(String id) {
        return null;
    }

    @Override
    public PageInfo<RefReqList> getList(Page page, RefReqList refReqList) {
        return null;
    }

    @Override
    public RefReqList getInfo(String id) {
        return null;
    }
}
